package com.hongkang.view;

import java.util.Map;

import com.hongkang.draw.EcgCoordinate;
import com.hongkang.draw.EcgDrawUtils;
import com.hongkang.draw.EcgPoint;
import com.hongkang.draw.EcgCoordinate.ENUM_KY;
import com.hongkang.draw.EcgCoordinate.ENUM_VX;
import com.hongkang.ecg.Constant;

import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

public class ScopeSurfaceView extends SurfaceView implements  SurfaceHolder.Callback{
	Boolean DEBUG = Constant.DEBUG;
	String TAG = "ScopeSurfaceView";
	
	public Map<Integer, Integer> mData;
	public ScopeSurfaceView(Context context) {
		super(context);
		if(DEBUG) Log.d(TAG,"on created1");
		//setWillNotDraw(false);
	}
	
	public ScopeSurfaceView(Context context, AttributeSet attrs){
		super(context, attrs);
		if(DEBUG) Log.d(TAG,"on created2");
		//setWillNotDraw(false);
	}
	
	public ScopeSurfaceView(Context context,AttributeSet attrs,int arg0){
		super(context, attrs, arg0);
		if(DEBUG) Log.d(TAG,"on created3");
		//setWillNotDraw(false);
	}
	
	//draw static scope
	/**
	 * draw subscope
	 */
	protected void drawSubStaticScope(SurfaceHolder holder,Map<Integer, Integer> data){
		EcgPoint<Float> size = new EcgPoint<Float>(
				(float) this.getWidth(),
				(float) this.getHeight());
		//coodinate
		EcgCoordinate coordinate = new EcgCoordinate(size,
				new EcgPoint<Float>(0f,0f), 
				size.y.intValue(), 
				size.x.intValue(), 
				ENUM_VX.ENUM_VX_25,
				ENUM_KY.ENUM_KY_10, 
				data.size() / 512);
		EcgDrawUtils.drawStaticScope(data,holder,
				coordinate,512, null);
	}
	
	@Override
	protected void onDraw(Canvas canvas) {
		if(DEBUG) Log.d(TAG,"on draw");
		super.onDraw(canvas);
	}

	@Override
	public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
		
	}

	@Override
	public void surfaceCreated(SurfaceHolder arg0) {
		if(DEBUG) Log.d(TAG,"on surface created");
	}

	@Override
	public void surfaceDestroyed(SurfaceHolder arg0) {
		
	}
	
	@Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		if(DEBUG) Log.d(TAG,widthMeasureSpec + " + " + heightMeasureSpec);
		super.onMeasure(widthMeasureSpec, heightMeasureSpec);
	}
	
	@Override
	protected void dispatchDraw(Canvas canvas) {
		if(DEBUG) Log.d(TAG,"dispatchDraw");
		super.dispatchDraw(canvas);
	}
	
	@Override
	protected void onAttachedToWindow() {
		if(DEBUG) Log.d(TAG,"attatched to window");
		super.onAttachedToWindow();
	}
}
